package com.jcli.jb51_net.article._175980开关按钮;

import javax.swing.*;
import java.awt.*;

/**
 * @author li
 */
public class NoButtonClickAnimation extends JButton {
    public NoButtonClickAnimation(String text) {
        super(text);
        // 禁用鼠标悬停效果
        setRolloverEnabled(false);
        // 禁用边框绘制
        setBorderPainted(false);
        // 禁用内容区域填充
        setContentAreaFilled(false);

        setSelectedIcon(new ImageIcon("./pic/Snipaste_2023-12-25_12-02-52.png"));
        setIcon(new ImageIcon("./pic/Snipaste_2023-12-25_12-03-24.png"));
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // 禁用点击动画  
        setRolloverIcon(getIcon());
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("No Button Click Animation");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);
        frame.setLayout(new FlowLayout());
        frame.add(new NoButtonClickAnimation(""));
        frame.setVisible(true);
    }
}